﻿using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Applet.RequestDto;
using VisionCloud.Domain.DtoModel.Applet.ResponseDto;
using VisionCloud.Domain.DtoModel.Ms;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Applet;

namespace VisionCloud.Api.Controllers.Applet
{
    /// <summary>
    /// 项目相关
    /// </summary>
    [SystemModule("小程序模块")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/applet/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "小程序模块")]
    public class ProjectController : ApiBaseController
    {
        public ProjectService ProjectService { get; set; }

        /// <summary>
        /// 模糊查询特定城市和用户相关的项目位置信息
        /// </summary>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<List<ProjectLocationDto>>))]
        public async Task<ApiResult> QueryProjectLocations(QueryProjectLocationDto query)
        {
            return await TryCatchAsync(ProjectService.QueryProjectLocations(query));
        }

        /// <summary>
        /// 获取项目楼栋信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<ProjectBuildingInfoDto>))]
        public async Task<ApiResult> GetProjectBuildingInfo(IdDto idDto)
        {
            return await TryCatchAsync(ProjectService.GetProjectBuildingInfo(idDto.Id));
        }

        /// <summary>
        /// 获取项目已测量楼层信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<WxProjectFloorResponse>))]
        public async Task<ApiResult> GetProjectFloorInfo(WxProjectBuildingDto query)
        {
            return await TryCatchAsync(ProjectService.GetProjectFloorInfo(query));
        }

        /// <summary>
        /// 获取城市列表
        /// </summary>
        [HttpGet]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<CityListDto>))]
        public async Task<ApiResult> GetCityList(string query)
        {
            return await TryCatchAsync(ProjectService.GetCityList(query));
        }

        /// <summary>
        /// 获取项目合格率排行榜
        /// </summary>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<ProjectQualificateDto>))]
        public async Task<ApiResult> GetProjectQualificationRates(PageRequest request)
        {
            return await TryCatchAsync(ProjectService.ProjectQualificationRates(request));
        }

        /// <summary>
        /// 从坐标获取城市名称
        /// </summary>
        [HttpPost]
        public async Task<ApiResult> GetCityNameFromLocation(LocationDto locaton)
        {
            return await TryCatchAsync(ProjectService.GetCityNameFromLocation(locaton));
        }

        /// <summary>
        /// 从详细地址获取坐标
        /// </summary>
        [HttpGet]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<LocationDto>))]
        public async Task<ApiResult> GetLocationFromAddress(string address)
        {
            return await TryCatchAsync(ProjectService.GetLocationFromAddress(address));
        }
    }
}